<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Category
 *
 * @property int $id
 * @property int $pid 父类id
 * @property string $cate_name 分类名称
 * @property string $cate_img 分类图片
 * @property string $path 商品路径
 * @property string|null $created_at
 * @property string|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Category whereCateImg($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Category whereCateName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Category whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Category whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Category wherePath($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Category wherePid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Category whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Category extends Model
{
    protected $table = 'goods_cate';

    public $timestamps = false;

    protected $guarded=[];
    public function storeData($data)
    {
        // 处理data为空的情况
        if (empty($data)) {
            return false;
        }
        //添加数据
        $result = $this->create($data);
        if ($result) {
            return $result->id;
        }else{
            return false;
        }
    }

    public function destroyData($id)
    {
        $result = $this->destroy($id);
        if($result){
            return true;
        }else{
            return false;
        }
    }

    public function updateData($data,$id)
    {
        $result = $this->where('id',$id)->update($data);
        if ($result) {
            return true;
        }else{
            return false;
        }
    }
}
